# -*- coding: utf-8 -*-
#
# @Author  : Yang
# @Email  : yangjiaxian@ibbd.net
# @Time    : 2023/3/6

from src.common.OptionMysql import OptionMysql


class FileServices():
    @staticmethod
    def fetch_data(customerId):
        """获取附件信息"""
        mysql = OptionMysql()
        sql = """SELECT * FROM `file` WHERE `customer_id`=%s AND `is_delete`=0"""
        res = mysql.fetch_data(sql, [customerId])
        return res

    @staticmethod
    def fetch_one(file_id):
        """获取附件信息"""
        mysql = OptionMysql()
        sql = """SELECT * FROM `file` WHERE `id`=%s AND `is_delete`=0"""
        res = mysql.fetch_one(sql, [file_id])
        return res

    @staticmethod
    def delete(file_id):
        """删除附件"""
        mysql = OptionMysql()
        sql = """update `file` set `is_delete`=1 where `id`=%s """
        res = mysql.update_one(sql, [file_id])
        return res

    @staticmethod
    def create(customerId, filename, filepath):
        """上传附件"""
        mysql = OptionMysql()
        data = {
            "customer_id": customerId,
            "filename": filename,
            "filepath": filepath,
        }
        affect_rows, file_id = mysql.insert_dict("file", data, True)
        return file_id
